package ar.edu.itba.pod.legajo48240.node;

import java.rmi.RemoteException;
import java.rmi.server.UnicastRemoteObject;
import java.util.ArrayList;
import java.util.List;

import ar.edu.itba.node.api.NodeStatistics;
import ar.edu.itba.node.api.StatisticReports;
import ar.edu.itba.pod.agent.market.AgentState;
import ar.edu.itba.pod.agent.runner.Agent;
import ar.edu.itba.pod.legajo48240.model.Host;


@SuppressWarnings("serial")
public class Statistics extends UnicastRemoteObject implements StatisticReports{
	
	private final Host localhost;
	
	public Statistics(Host localhost) throws RemoteException {
		super();
		this.localhost=localhost;
	}
	

	@Override
	public NodeStatistics getNodeStatistics() throws RemoteException {
		
		List<Agent> agents = localhost.simulation().getAgentsRunning();
		List<AgentState> agentStates=new ArrayList<AgentState>();
		for(Agent a: agents){
			agentStates.add(a.state());
		}
		return new NodeStatistics(agents.size(), agentStates);
	}

}
